package com.comleader.uap.controller;

import static com.comleader.common.core.web.page.ResultBuilder.getPageResult;
import static com.comleader.uap.common.response.Result.success;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.comleader.common.core.web.page.PageResult;
import com.comleader.uap.common.page.PageQuery;
import com.comleader.uap.common.response.Result;
import com.comleader.uap.pojo.query.UrlPushQuery;
import com.comleader.uap.pojo.vo.UrlPushVO;
import com.comleader.uap.service.UrlLibrarySyncService;
import com.github.pagehelper.PageHelper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description 网址推送
 * @Auhtor 连新景
 * @Date 2024/11/25 17:08
 */
@Api(tags = "网址推送")
@Validated
@RestController
@RequestMapping("/url-push")
public class UrlPushController {
    @Resource
    private UrlLibrarySyncService urlLibrarySyncService;

    /**
     * @Description 分页查询
     * @Auhtor 连新景
     * @Date 2024/11/25 17:03
     * @param query
     * @return com.comleader.uap.common.response.Result<com.comleader.uap.common.page.PageData <
     *         com.comleader.uap.pojo.vo.UrlPushVO>>
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/list")
    public Result<PageResult<UrlPushVO>> list(@Valid @RequestBody PageQuery<UrlPushQuery> query) {
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        return success(getPageResult(urlLibrarySyncService.selectList(query.getQueryParams())));
    }

    /**
     * @Description 导出
     * @Auhtor 连新景
     * @Date 2024/11/26 10:13
     * @param query
     * @param response
     */
    @ApiOperation(value = "导出")
    @PostMapping("/export")
    public void export(@RequestBody UrlPushQuery query, HttpServletResponse response) throws IOException {
        urlLibrarySyncService.export(query, response);
    }

}
